//
//  SingleCell.m
//  悠狸
//
//  Created by dlios on 15-8-27.
//  Copyright (c) 2015年 Dung. All rights reserved.
//

#import "SingleCell.h"
#import "SingleModel.h"
#import "UIImageView+WebCache.h"
#import "ShopModel.h"
@interface SingleCell()
@property(nonatomic, retain)UIImageView *imageV;
@property (nonatomic, retain)UILabel *title;
@property (nonatomic, retain)UILabel *price;
@property (nonatomic, retain)UILabel *count;

@end
@implementation SingleCell

- (void)dealloc
{
    [_imageV release];
    [_title release];
    [_count release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.contentView.layer.cornerRadius = 10;
        self.contentView.clipsToBounds = YES;
        [self create];
    }
    return self;
}

- (void)create
{
    UIView *aview = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height)] autorelease];
    aview.backgroundColor = [UIColor colorWithRed:252 / 255.0 green:244 / 255.0 blue:224 / 255.0 alpha:1.0];
    [self.contentView addSubview:aview];
    
    self.imageV = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, 170 *OffHeight)] autorelease];
    
//    _imageV.backgroundColor = [UIColor redColor];
    
    [aview addSubview:_imageV];
    
    self.title = [[[UILabel alloc] initWithFrame:CGRectMake(0, 160*OffHeight, self.contentView.frame.size.width, 25*OffHeight)] autorelease];
    _title.backgroundColor = [UIColor colorWithRed:252 / 255.0 green:244 / 255.0 blue:224 / 255.0 alpha:1.0];
    self.title.textAlignment = NSTextAlignmentCenter;
    _title.numberOfLines = 2;
    _title.font = [UIFont systemFontOfSize:13];
    _title.textColor = [UIColor blackColor];
    [aview addSubview:_title];
    
    self.price = [[[UILabel alloc] initWithFrame:CGRectMake(15*OffWidth, 210*OffHeight, 150*OffWidth, 30*OffHeight)] autorelease];
    _price.numberOfLines = 0;
    _price.textAlignment = NSTextAlignmentLeft;
    _price.font = [UIFont systemFontOfSize:15];
    _price.backgroundColor = [UIColor colorWithRed:252 / 255.0 green:244 / 255.0 blue:224 / 255.0 alpha:1.0];
    _price.textColor = [UIColor redColor];
    [aview addSubview:_price];
    
    self.count = [[[UILabel alloc] initWithFrame:CGRectMake(105*OffWidth, 210*OffHeight, 100*OffWidth, 30*OffHeight)] autorelease];
    _count.numberOfLines = 0;
    _count.backgroundColor = [UIColor colorWithRed:252 / 255.0 green:244 / 255.0 blue:224 / 255.0 alpha:1.0];
    _count.font = [UIFont systemFontOfSize:15];
    _count.textAlignment = NSTextAlignmentLeft;
    [aview addSubview:_count];
    
    UIView *bview = [[[UIView alloc] initWithFrame:CGRectMake(75*OffWidth, 215*OffHeight, 30*OffWidth, 20*OffHeight )] autorelease];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"100" ofType:@"png"] ;
    
    UIImage *image = [UIImage imageWithContentsOfFile:path];
    
    UIImageView *imageV = [[UIImageView alloc] initWithImage:image];
    [bview addSubview:imageV];
    [aview addSubview:bview];
}
- (void)setsingleModeL:(SingleModel *)model
{
//    
    [_imageV sd_setImageWithURL:[NSURL URLWithString:model.cover_image_url] placeholderImage:[UIImage imageNamed:@"000.jpg"]];
    
    _title.text = model.name;
    _price.text = [NSString stringWithFormat:@"%@", model.price];
    _count.text = [NSString stringWithFormat:@"%@", model.favorites_count];
}
- (void)setShopModel:(ShopModel *)model
{
    [_imageV sd_setImageWithURL:[NSURL URLWithString:model.cover_image_url] placeholderImage:[UIImage imageNamed:@"000.jpg"]];
    
    self.title.text =[NSString stringWithFormat:@"%@", model.name];
    _price.text = [NSString stringWithFormat:@"%@", model.price];
    _count.text = [NSString stringWithFormat:@"%ld", (long)model.favorites_count];
}
@end
